<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Extracts exchange rates from ČNB
 *
 * @author Michal
 */
class ADS_CNBReader implements ADS_Format {
    
    //document
    private $doc = array();
    
    public function parse($string){
        $export = array();
        //get rows
        $rows = explode("\n", $string);
        //unset first two rows (header)
        unset($rows[0],$rows[1]);
        foreach($rows as &$row){
            //extract columns
            list($country, $currency, $amount, $code, $rate) = explode('|', $row);
            $export[strtolower($code)] = array(
                'country'  => $country,
                'currency' => $currency,
                'amount'   => $amount,
                'rate'     => $rate,
            );
        }
        $this->doc = $export;
    } 
    
    public function toArray(){
        return $this->doc;
    }
}

?>
